<template>
  <a-card :bordered="false">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="支付机构" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="payOrg">
              <j-dict-select-tag type="list" v-model="model.payOrg" dictCode="pay_org" placeholder="请选择支付机构" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商户号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="merchantNo">
              <a-input v-model="model.merchantNo" placeholder="请输入商户号"  ></a-input>
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="商户私钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="privateKey">
              <a-textarea v-model="model.privateKey" rows="4" placeholder="请输入商户私钥" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="支付机构公钥" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="publicKey">
              <a-textarea v-model="model.publicKey" rows="4" placeholder="请输入支付机构公钥" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="安全校验码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiKey">
              <a-textarea v-model="model.apiKey" rows="4" placeholder="请输入安全校验码" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="对账用户名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiKey">
              <a-textarea v-model="model.username" rows="4" placeholder="请输入对账用户名" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="对账用户密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiKey">
              <a-textarea v-model="model.password" rows="4" placeholder="请输入对账用户密码" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="文件解压密码" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="apiKey">
              <a-textarea v-model="model.zipPassword" rows="4" placeholder="文件解压密码" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24" align="center">
            <!--<a-button @click="emptyCurrForm" type="default" htmlType="button" icon="sync">重置</a-button>-->
            <a-button @click="submitForm" type="primary" htmlType="button" icon="form">保存</a-button>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>

  </a-card>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'TempleMerchantInfoForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/temple.pay/templeMerchantInfo/add",
          edit: "/temple.pay/templeMerchantInfo/edit",
          get: "/temple.pay/templeMerchantInfo/getOne"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      // this.modelDefault = JSON.parse(JSON.stringify(this.model));
      httpAction(this.url.get, null, 'get').then((res) => {
        if (res.success) {
          this.model = res.result
        } else {
          this.$message.error(res.message)
        }
      })
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>